package com.clip.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.clip.entity.Userassina;

@Repository
public class UserassinaDAO extends BasicDao  {
    private static final Log log = LogFactory.getLog(UserassinaDAO.class);

    
    public void save(Userassina transientInstance) {
        log.debug("saving Userassina instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(Userassina persistentInstance) {
        log.debug("deleting Userassina instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Userassina findById( java.lang.Integer id) {
        log.debug("getting Userassina instance with id: " + id);
        try {
        	Userassina instance = (Userassina) getSession().get(Userassina.class, id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
	public List findAll() {
		log.debug("finding all Userassina instances");
		try {
			String queryString = "from Userassina";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
    public Userassina merge(Userassina detachedInstance) {
        log.debug("merging Userassina instance");
        try {
        	Userassina result = (Userassina) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Userassina instance) {
        log.debug("attaching dirty Userassina instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Userassina instance) {
        log.debug("attaching clean Userassina instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public List findByQuery(String query) {
		return findByQuery(query,null);
	}
	
	public List findByQuery(String queryStr,Object...args ){
		Query query =getSession().createQuery(queryStr);
		if(args!=null&&args.length>0){
			for (int i = 0; i < args.length; i++) {
				query.setParameter(i, args[i]);
			}
		}
		return query.list();
	}
}